<template>
	<el-row>
		<el-col :span="3">
			<el-row>
				<el-col :span="8" class="title">卡号：</el-col>
				<el-col :span="15"><el-input placeholder="请输入内容" v-model="patientID"></el-input></el-col>
			</el-row>
		</el-col>
		<el-col :span="3">
			<el-row>
				<el-col :span="8" class="title">姓名：</el-col>
				<el-col :span="15"><el-input placeholder="请输入内容" v-model="patientName"></el-input></el-col>
			</el-row>
		</el-col>
		<el-col :span="3">
			<el-row>
				<el-col :span="8" class="title">性别：</el-col>
				<el-col :span="15">
					<el-select v-model="sex" placeholder="请选择">
						<el-option
						v-for="item in sexs"
						:key="item.value"
						:label="item.label"
						:value="item.value">
					</el-option>
				</el-select>
			</el-col>
		</el-row>

	</el-col>
	<!-- <el-col :span="3">
		<el-row>
			<el-col :span="8" class="title">年龄段：</el-col>
			<el-col :span="15">
				<el-select v-model="ageType" placeholder="请选择">
						<el-option
						v-for="item in ageTypes"
						:key="item.value"
						:label="item.label"
						:value="item.value">
					</el-option>
				</el-select>
			</el-col>
		</el-row>
	</el-col> -->
	<el-col :span="3">
		<el-row>
			<el-col :span="12">
				<el-select v-model="ageStage">
						<el-option
						v-for="item in ageStages"
						:key="item.value"
						:label="item.label"
						:value="item.value">
					</el-option>
			</el-select>
			</el-col>
			<el-col :span="11"><el-input :placeholder='ageTip' v-model="age" type="number" min='0' step='1'></el-input></el-col>
		</el-row>
		
	</el-col>
	<el-col :span="3">
		<el-row>
			<el-col :span="8" class="title">电话：</el-col>
			<el-col :span="15"><el-input placeholder="请输入内容" v-model="telephone"></el-input></el-col>
		</el-row>
		
	</el-col>
	<el-col :span="6">
		<el-row>
			<el-col :span="4" class="title">地址：</el-col>
			<el-col :span="20"><el-input placeholder="请输入内容" v-model="address"></el-input></el-col>
		</el-row>
		
	</el-col>
	<el-col :span="3">
		<el-row>
			<el-col :span="18" style="text-align:center;line-height:20px;">
				<span style="font-size:10pt;" title="仅当手工设置的等级高于系统计算的等级时有效">手工调整等级</span>
				<el-rate v-model="humanLight" :max='4'>
				 </el-rate>
			</el-col>
			<el-col :span="6"><light></light></el-col>
		</el-row>
		
	</el-col>
</el-row>
</template>
<script type="text/javascript">
import Light from '@/components/Light'
export default{
	name:'BaseInfo',
	components:{Light},
	data() {
		return {
			ageTip:'请输入年龄',
			ageTips:[
				'请输入月数',
				'请输入年龄'
			],
			sexs: [{
				value: '男',
				label: '男'
			}, {
				value: '女',
				label: '女'
			}],
			patientID:'',
			patientName:'',
			sex: '',
			age: '',
			telephone: '',
			address: '',
			ageType:'',
			ageStages:[ {
				value: '年龄',
				label: '年龄'
			},{
				value: '月数',
				label: '月数'
			}],
			ageStage:'年龄',
			ageTypes:[ {
				value: '成人',
				label: '成人'
			},{
				value: '1岁内婴儿',
				label: '1岁内婴儿'
			},{
				value: '1-3岁儿童',
				label: '1-3岁儿童'
			},{
				value: '4-7岁儿童',
				label: '4-7岁儿童'
			},{
				value: '8-14岁儿童',
				label: '8-14岁儿童'
			}],
			startDate:'',
			humanLight:1
		}
	},
	methods:{
		getBaseInfoGroups:function(){
			var baseInfoGroups = '';
			//判断性别编号
			if (this.sex == "男") {
				baseInfoGroups += 'h1,';
			}else if (this.sex == "女") {
				baseInfoGroups += 'h2,';
			}
			//判断类型编号
			if (this.ageType == '1岁内婴儿') {
				baseInfoGroups += 'i1,';
			}else if (this.ageType == '1-3岁儿童') {
				baseInfoGroups += 'i2,';
			}else if (this.ageType == '4-7岁儿童') {
				baseInfoGroups += 'i3,';
			}else if (this.ageType == '8-14岁儿童') {
				baseInfoGroups += 'i4,';
			}else if (this.ageType == '成人') {
				baseInfoGroups += 'i5,';
			}
			//判断年龄编号
			if (this.age >=15 && this.age <=65) {
				baseInfoGroups += 'j2,';
			}else if (this.age > 65) {
				baseInfoGroups += 'j3,';
			}else{
				baseInfoGroups += 'j1,';
			}
			this.$store.commit({
					type:"setBaseInfoGroups",
					baseInfoGroups:baseInfoGroups
				});
		},
		exportData:function(){
			if (this.startDate=='') {
				this.startDate = new Date();
			}
			var BaseInfoData = {
				patientID: this.patientID,
				patientName: this.patientName,
				sex: this.sex,
				ageType: this.ageType,
				age: this.age,
				telephone: this.telephone,
				address: this.address,
				startDate: this.startDate,
				humanLight:this.humanLight
			};
			this.$store.commit({
				type:"setBaseInfoData",
				BaseInfoData: BaseInfoData
			});
		}
	},
	computed:{
		recordData(){
			return this.$store.state.recordData;
		}
	},
	watch:{
		age(curVal,oldVal){
			if (curVal!='') {
				if (this.ageStage=='月数') {
					this.ageType = "1岁内婴儿";
				}else if (curVal<=3) {
					this.ageType = '1-3岁儿童';
				}else if (curVal<=7&&curVal>3) {
					this.ageType = '4-7岁儿童';
				}else if (curVal<=14&&curVal>7) {
					this.ageType == '8-14岁儿童';
				}else{
					this.ageType = '成人';
				}

			}
			this.$store.commit({
					type:"setAge",
					age:curVal
				});
			this.getBaseInfoGroups();
			this.exportData();
		},
		ageType(curVal,oldVal){
			this.$store.commit({
					type:"setAgeType",
					ageType:curVal
				});
			this.getBaseInfoGroups();
			this.exportData();
		},
		ageStage(curVal,oldVal){
			this.age="";
			if (curVal=='年龄') {
				this.ageTip = this.ageTips[1];
			}else{
				this.ageTip = this.ageTips[0];
			}
		},
		sex(curVal,oldVal){
			//调用一下统计第一部分症状信息
			this.getBaseInfoGroups();
			this.exportData();
		},
		patientID(curVal,oldVal){
			this.exportData();
		},
		patientName(curVal,oldVal){
			this.exportData();
		},
		telephone(curVal,oldVal){
			this.exportData();
		},
		address(curVal,oldVal){
			this.exportData();
		},
		recordData:{
			handler(curVal,oldVal){
				this.startDate = curVal.recordStart?new Date(Date.parse(curVal.recordStart.replace(/-/g, "/"))):"";
				this.patientID = curVal.recordCard?curVal.recordCard:"";
				this.patientName = curVal.recordName?curVal.recordName:"";
				this.sex = curVal.recordSex?curVal.recordSex:"";
				this.ageType = curVal.recordType?curVal.recordType:"";
				this.age = curVal.recordAge?curVal.recordAge:"";
				this.telephone = curVal.recordTel?curVal.recordTel:"";
				this.address = curVal.recordAddress?curVal.recordAddress:"";
				this.humanLight = curVal.recordHumanLight?parseInt(curVal.recordHumanLight):1;
			},
			deep:true
		},
		humanLight:{
			handler(curVal,oldVal){
				this.$store.commit({
					type: "setHumanLights",
					humanLights: curVal
				});
				this.exportData();
			}
		}
	}
}
</script>
<style type="text/css" scoped>
.el-row{
	margin-top: 5px;
	text-align: left;
	line-height: 40px;
}
.title{
	text-align: right;
}
</style>